// d:\byte\tiktok-applet-v3 - 建材\pages\nav\nav.js
const model = require('../../public/model/env.js');
const background = tt.getStorageSync('background');
const url = model.api_pro_url();
const key = model.key();
const appid = model.appid();
Page({
  data: {
    data2: '立即跳转',
    className: '',
    navigateToMiniProgram: 'navigateToMiniProgram',
    navappId: ''
  },

  onLoad: function () {
    const requestUrlorder = `${url}/index.php/api/onload`;
    const navs = {
      url: requestUrlorder,
      data: {
        appid: appid,
        key: key,
        
      },
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      dataType: 'json',
    };
    // console.log(orders);
    tt.request({
      ...navs,
      success: (res) => {
        const data = res.data;
        console.log(data);
        console.log(data.miyue);
        if (data.code == 200) {
          // console.log('数组包含的元素数量:', data.data.length);
          this.setData({
            navappId:data.miyue,
          });
        }
      },
      fail: (err) => {
        console.log(err);
      }
    });

    if (background == 'naight') {
      this.setData({
        className: 'containerdark'
      })
    } else {
      this.setData({
        className: 'containerlight'
      })
    }
  },
  requestgua() {
    // let that = this
    // navigateToMiniProgram = 'navigateToMiniProgram',
    tt[this.data.navigateToMiniProgram]({

      appId: this.data.navappId,
      path: "pages/input/input?appid="+appid+"&key="+key,
      // path: "pages/input/input?arg1=ascii&arg2=" + encodeURIComponent("中文"),
      extraData: {
        arg3: "hello",
      },
      envVersion: "current",
      success() {
        console.log("接口调用成功");
      },
      fail(errMsg) {
        console.log(errMsg);
        // that.setData({
        //   result: "接口调用失败,小程序跳转需传入配置项: 必填：appId（要跳转的小程序ID），选填：path（要跳转的小程序页面路径（不传则默认打开首页））、extraData（需要传递给目标小程序的数据）、envVersion（要打开的小程序版本）等"
        // });
      },
      complete() {
        console.log("接口调用了");
      }
    });
  }
})